/*
 * Copyright 2000-2020 ALPHA LAB.Inc All Rights Reserved.
 */
package com.alphalab.moonlight.demo.impl.context;
 
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alphalab.framework.context.GeneralQueryContext;
import com.alphalab.framework.domain.dto.ListResultVO;
import com.alphalab.framework.exception.MoRuntimeException;
import com.alphalab.framework.log.IMoLog;
import com.alphalab.framework.log.MoLogFactory;
import com.alphalab.moonlight.demo.service.context.IAirlineQueryContext;
import com.alphalab.moonlight.demo.service.model.AirlineVO;
import com.alphalab.moonlight.demo.service.model.FlightQueryParamVO;
import com.alphalab.moonlight.demo.service.model.FlightTrendAnalyseVO;
import com.alphalab.moonlight.demo.service.model.FlightTrendQueryParamVO;
import com.alphalab.moonlight.demo.service.model.PassengerTravelVO;
import com.alphalab.moonlight.demo.service.role.IAirlineQueryRole;

/**
 * AirlineQueryContext.
 * @author allen 
 * @version 1.0.0 2018年2月20日
 */
@Controller 
@RequestMapping("/airlineQueryContext")
public class AirlineQueryContext extends GeneralQueryContext<AirlineVO, IAirlineQueryRole> 
	implements IAirlineQueryContext {
	
	/**
	 * logger.
	 */
	private static final IMoLog logger = MoLogFactory.getLog(AirlineQueryContext.class);

	/**
	 * 手动注入setAirlineQueryRole.
	 * @param airlineQueryRole airlineQueryRole
	 */
	@Autowired
	public void setAirlineQueryRole(final IAirlineQueryRole airlineQueryRole) { 
		super.setGeneralQueryRole(airlineQueryRole);
	}

	/**
	 * 根据航班查询条件对象VO查询航班结果集.
	 * @param flightQueryParamVO 航班查询条件对象VO
	 * @return List<AirlineVO>
	 */
	@Override
	public ListResultVO<AirlineVO> getAirlineList(final FlightQueryParamVO flightQueryParamVO) {
		logger.info("into AirlineQueryContext getAirlineList");
		List<AirlineVO> voList =  new ArrayList<AirlineVO>();
		ListResultVO<AirlineVO> rstList = new ListResultVO<AirlineVO>();
		try {
			voList = getGeneralQueryRole().getAirlineList(flightQueryParamVO);
			rstList = new ListResultVO<AirlineVO>(voList);
		} catch (Exception ex) {
			logger.error(ex);
			rstList = new ListResultVO<AirlineVO>(ex);
		}
		return rstList;
	}

	/**
	 * 根据航班查询条件对象VO分页查询航班结果集.
	 * @param flightQueryParamVO 航班查询条件对象VO
	 * @param pageIndex 第几页
	 * @param pageSize 每页的记录数
	 * @return List<AirlineVO>
	 */
	@Override
	public ListResultVO<AirlineVO> getAirlineListByPage(final FlightQueryParamVO flightQueryParamVO, 
			final int pageIndex, final int pageSize) {
		List<AirlineVO> voList =  new ArrayList<AirlineVO>();
		ListResultVO<AirlineVO> rstList = new ListResultVO<AirlineVO>();
		try {
			voList = getGeneralQueryRole().getAirlineList(flightQueryParamVO, pageIndex, pageSize);
			rstList = new ListResultVO<AirlineVO>(voList);
		} catch (Exception ex) {
			logger.error(ex);
			rstList = new ListResultVO<AirlineVO>(ex);
		}
		return rstList;
	}

	/**
	 * 根据航班查询条件对象VO查询旅客行程结果集.
	 * @param flightQueryParamVO 航班查询条件对象VO
	 * @return List<PassengerTravelVO>
	 */
	@Override
	public ListResultVO<PassengerTravelVO> getPassengerTravelList(final FlightQueryParamVO flightQueryParamVO) {
		List<PassengerTravelVO> voList =  new ArrayList<PassengerTravelVO>();
		ListResultVO<PassengerTravelVO> rstList = new ListResultVO<PassengerTravelVO>();
		try {
			voList = getGeneralQueryRole().getPassengerTravelList(flightQueryParamVO); 
			rstList = new ListResultVO<PassengerTravelVO>(voList);
		} catch (Exception ex) {
			logger.error(ex);
			rstList = new ListResultVO<PassengerTravelVO>(ex);
		}
		return rstList;
	}

	/**
	 * 根据航班查询条件对象VO查询航班趋势分析结果集.
	 * @param flightTrendQueryParamVO 航班趋势分析结果VO
	 * @return List<FlightTrendAnalyseVO>
	 */
	@Override
	public ListResultVO<FlightTrendAnalyseVO> getFlightTrendAnalyseResult(
			final FlightTrendQueryParamVO flightTrendQueryParamVO) { 
		List<FlightTrendAnalyseVO> voList =  new ArrayList<FlightTrendAnalyseVO>();
		ListResultVO<FlightTrendAnalyseVO> rstList = new ListResultVO<FlightTrendAnalyseVO>();
		try {
			voList = getGeneralQueryRole().getFlightTrendAnalyseResult(flightTrendQueryParamVO);
			rstList = new ListResultVO<FlightTrendAnalyseVO>(voList);
		} catch (MoRuntimeException ex) {
			logger.error(ex);
			rstList = new ListResultVO<FlightTrendAnalyseVO>(ex);
		}
		return rstList;
	}

}
